﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data;

using QLTTAN.DTO;
namespace QLTTAN.DAL
{
    public class CT_LopHocDAL
    {
        ConnectionData conn;

        public DataRow CT_LopHoc_GetInfo(CT_LopHocDTO CT_LH_DTO)
        {
            conn = new ConnectionData();

            int Nparameter = 1;
            string[] name = new string[Nparameter];
            object[] value = new object[Nparameter];

            name[0] = "MaHV";
            value[0] = CT_LH_DTO.MaHV;

            return conn.GetData("CT_LOPHOC_GETINFO", name, value, Nparameter).Rows[0];
        }

        public DataTable CT_LopHoc_FindHV(KhoaHocDTO KH_DTO, LoaiLopHocDTO LLH_DTO, HocVienDTO HV_DTO)
        {
            conn = new ConnectionData();

            int Nparameter = 5;
            string[] name = new string[Nparameter];
            object[] value = new object[Nparameter];

            name[0] = "TenKhoaHoc";
            value[0] = KH_DTO.TenKhoaHoc;
            name[1] = "TenLoaiLop";
            value[1] = LLH_DTO.TenLoaiLop;
            name[2] = "TenHV";
            value[2] = HV_DTO.TenHV;
            name[3] = "DiaChi";
            value[3] = HV_DTO.GioiTinh;
            name[4] = "MaCTLH";
            value[4] = HV_DTO.DiaChi;

            return conn.GetData("CT_LOPHOC_FINDHV", name, value, Nparameter);
        }

        public DataTable CT_LopHoc_Load(CT_LopHocDTO CT_LH_DTO)
        {
            conn = new ConnectionData();

            int Nparameter = 1;
            string[] name = new string[Nparameter];
            object[] value = new object[Nparameter];

            name[0] = "MaLop";
            value[0] = CT_LH_DTO.MaLop;

            return conn.GetData("CT_LOPHOC_LOAD_MaLop", name, value, Nparameter);
        }

        public int CT_LopHoc_Insert(CT_LopHocDTO CT_LH_DTO)
        {
            conn = new ConnectionData();

            int Nparameter = 2;
            string[] name = new string[Nparameter];
            object[] value = new object[Nparameter];

            name[0] = "MaLop";
            value[0] = CT_LH_DTO.MaLop;
            name[1] = "MaHV";
            value[1] = CT_LH_DTO.MaHV;

            return conn.UpdateData("CT_LOPHOC_INSERT", name, value, Nparameter);
        }

        public int CT_LopHoc_Update(CT_LopHocDTO CT_LH_DTO)
        {
            conn = new ConnectionData();

            int Nparameter = 3;
            string[] name = new string[Nparameter];
            object[] value = new object[Nparameter];

            name[0] = "MaCTLH";
            value[0] = CT_LH_DTO.MaCTLH;
            name[1] = "Diem";
            value[1] = CT_LH_DTO.Diem;
            name[2] = "Dat";
            value[2] = CT_LH_DTO.Dat;

            return conn.UpdateData("CT_LOPHOC_UPDATE", name, value, Nparameter);
        }

        public int CT_LopHoc_Delete(CT_LopHocDTO CT_LH_DTO)
        {
            conn = new ConnectionData();

            int Nparameter = 1;
            string[] name = new string[Nparameter];
            object[] value = new object[Nparameter];

            name[0] = "MaCTLH";
            value[0] = CT_LH_DTO.MaCTLH;

            return conn.UpdateData("CT_LOPHOC_DELETE", name, value, Nparameter);
        }
    }
}
